Attribute VB_Name = "ModClassFinder"

Type wndClass
    style As Long
    lpfnwndproc As Long
    cbClsextra As Long
    cbWndExtra2 As Long
    hInstance As Long
    hIcon As Long
    hCursor As Long
    hbrBackground As Long
    lpszMenuName As String
    lpszClassName As String
End Type


Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type



Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, _
                                                        lpdwProcessId As Long) As Long

Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Declare Function GetClassLong Lib "user32" Alias "GetClassLongA" (ByVal hwnd As Long, _
                                                                  ByVal nIndex As Long) As Long

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
                                                                   ByVal lpWindowName As String) As Long
                                                                                         
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, _
                                                                  ByVal lpClassName As String, _
                                                                  ByVal nMaxCount As Long) _
                                                                  As Long

Declare Function GetDesktopWindow Lib "user32" () As Long

Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, _
                                                                        ByVal lpString As String, ByVal cch As Long) _
                                                                        As Long

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
                                                                    ByVal dwNewLong As Long) As Long

Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal _
                                                  hWndInsertAfter As Long, ByVal x As Long, _
                                                  ByVal y As Long, ByVal cx As Long, ByVal cy As Long, _
                                                  ByVal wFlags As Long) As Long

Declare Function GetActiveWindow Lib "user32" () As Long

Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long

Declare Function GetForegroundWindow Lib "user32" () As Long

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
                                                                ByVal wMsg As Long, ByVal wParam As Long, _
                                                                lParam As Any) As Long

Declare Function GetClassInfo Lib "user32" Alias "GetClassInfoA" (ByVal hInstance As Long, _
                                                                  ByVal lpClassName As String, _
                                                                  lpWndClass As wndClass) As Long

Public Const WM_ACTIVATE = &H6
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = -1
Public Const GW_CHILD = 5
Public Const GW_HWNDNEXT = 2



Public Function GetOpenWindowNames() As Long
Dim lngDeskTopHandle As Long
Dim lngHand As Long
Dim strName As String * 255
Dim lngWindowCount As Long

lngDeskTopHandle = GetDesktopWindow()

lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)

lngWindowCount = 1

Do While lngHand <> 0
     
     GetWindowText lngHand, strName, Len(strName)
     
     lngHand = GetWindow(lngHand, GW_HWNDNEXT)
     
     If Left$(strName, 1) <> vbNullChar Then
          g = Left$(strName, InStr(1, strName, vbNullChar))
         
         
          frmClassFinder.lstOpenWindows.AddItem Left$(strName, InStr(1, strName, vbNullChar))
          lngWindowCount = lngWindowCount + 1
1
     End If
Loop

GetOpenWindowNames = lngWindowCount

End Function
